package 小红取数;

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    static int N = 1010, n, k;
    static long[] arr = new long[N];
    static long[][] f = new long[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        k = in.nextInt();
        for (int i = 1; i <= n; i++) {
            arr[i] = in.nextLong();
        }
        for (int i = 0; i <=n ; i++) {
            Arrays.fill(f[i],Long.MIN_VALUE);
        }
        f[0][0]=0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < k; j++) {
                f[i][j]=Math.max(f[i-1][j],f[i-1][(int) ((j-arr[i]%(long)k+(long)k )%(long)k)]+arr[i]);
            }
        }
        if(f[n][0]==Long.MIN_VALUE||f[n][0]==0){
            System.out.println(-1);
        }else {
            System.out.println(f[n][0]);
        }
    }
}